<template>
  <div id="app">
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  name: 'app',
  methods:{
    socketMessage(data){
        var _this = this;
        var msg = data.msg;
        var source = data.source;
        //【102报告单/202预约/401采样】
        //其他：
        //100~199 跳转报告单
        //200~399 跳转预约
        //400~499 跳转采样
        //500~599 跳转收样
        //600~699 跳转标本箱
        if(source >= 100 && source <= 199) source = 100;
        if(source >= 200 && source <= 399) source = 200;
        if(source >= 300 && source <= 499) source = 400;
        if(source >= 500 && source <= 599) source = 500;
        if(source >= 600 && source <= 699) source = 600;
        switch (source) {
          //报告
          case 100:
            _this.$notify.info({
              title: msg,
              message: "点击处理",
              onClick: function () {
                _this.$router.push({path: '/report/reportManagement'})
                _this.$notify.closeAll()
              },
              duration: 300000
            });
            _this.report();
           break;
          //预约
          case 200:
            _this.$notify.info({
              title: msg,
              message: "点击处理",
              onClick: function () {
                _this.$router.push({path: '/appoint/appointManagement'})
                _this.$notify.closeAll()
              },
              duration: 300000
            });
            _this.subscribe();
            break;
          //采样
          case 400:
            _this.$notify.info({
              title: msg,
              message: "点击处理",
              onClick: function () {
                _this.$router.push({path: '/sample/sampleApplyManagement'})
                _this.$notify.closeAll()
              },
              duration: 300000
            });
            _this.samplingPayment();
            break;
          //收样
          case 500:
            _this.$notify.info({
              title: msg,
              message: "点击处理",
              onClick: function () {
                _this.$router.push({path: '/collect/collectHospManagement'})
                _this.$notify.closeAll()
              },
              duration: 300000
            });
            _this.samplingPayment();
            break;
          //标本箱
          case 600:
            _this.$notify.info({
              title: msg,
              message: "点击处理",
              onClick: function () {
                _this.$router.push({path: '/equip/specimenManagement'})
                _this.$notify.closeAll()
              },
              duration: 300000
            });
             _this.overtimeTemperature();
            break;
            //其他
          default:
           // this.radioUrlOvertime = '../static/audio/overtime_temperature.mp3'
            _this.$notify.info({
              title: msg,
              onClick: function () {
                this.$notify.closeAll()
              },
                duration: 3000
            });
            _this.msgDingdong();
            break;
        }
      },
    pageDestroyed(){
      this.socket.emit('loginOut');
    }
  },
  destroyed(){
      window.addEventListener( 'unload', e => this.pageDestroyed() );
  },
  mounted(){
    let token = this.$store.getters.token;
    if(token!=null){
      this.socket.emit('client', this.$store.getters.userId) //刷新传token
    }
    // 一定要移除旧的message监听，否则会出现重复监听的状况
    this.socket.removeListener('message');
    this.socket.on('message',(data) =>{
      console.log('Socket-消息：',data)
      this.socketMessage(data);
    });

  }
}

</script>

<style>
  html,body{
    font-size: 12px;
    height: 100%;
    margin: 0;
  }
  #app {
    height: 100%;
  }
  .el-notification.right{
    cursor: pointer;
  }
</style>
